import {mapMutations} from 'vuex'

export default {
    ...mapMutations([
        'upIndexInfo',
    ]),
	//改变类型
	changeType(value){
		this.formData.reportType = this.typeList[value].code
	},
	//改变紧急类型
	changeSysDictType(value){
		this.formData.emergencyDegree = this.sysDictTypeList[value].code
	},
	submit(){
		let that = this
		var params = that.formData
		that.$httpRequest.request({
			that: that,
			url: 'report/add',
			params: params,
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.$toast.msg(res.message, {
						icon: 1
					})
					setTimeout(()=>{
						uni.navigateBack({
							delta: 1
						})
					},300)
				} else {
					that.$toast.alert({
						content: res.message,
						callback: result => {
							if (result.confirm) {
								
							}
						}
					})	
				}
			}
		})
	},
	handlerUpload() {
		let that = this;
		that.$httpRequest.handlerUploadWx(res => {
			if (res.code === that.$httpConfig.SUCCESS_CODE) {
				that.wordList.push(res.data)
				var planFileId = that.wordList.map((item,index)=>{
						return item = item.id
					})
				that.formData.reportFileId = planFileId
				console.log(res.data)
			}
		});
	},
	handlerUpload() {
		let that = this;
		that.$httpRequest.handlerUploadPic(res => {
			if (res.code === that.$httpConfig.SUCCESS_CODE) {
				 that.wordList.push(res.data)
				 var planFileId = that.wordList.map((item,index)=>{
				 		return item = item.id
				 	})
				 that.formData.reportFileId = planFileId
				 console.log(res.data)
			}
		})
	},
	getPeople() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'sysUser/getProjectUser',
			params: {
				"filterMe":false
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.peopleList = res.data.map((item,index)=>{
						return {
							label:item.name,value:item.id
						}
					})
					console.log(that.peopleList)
				} else {
					that.$toast.alert({
						content: res.message,
						callback: result => {
							if (result.confirm) {
								uni.navigateBack({
									delta: 1
								})
							}
						}
					})
				}
			}
		})
	},
	//获取报事类型
	getType() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'sysDictType/dropDown',
			params: {
				code: 'report_type',
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.typeList = res.data
				} else {
					that.$toast.alert({
						content: res.message,
						callback: result => {
							if (result.confirm) {
								uni.navigateBack({
									delta: 1
								})
							}
						}
					})
				}
			}
		})
	},
	getSysDictType() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'sysDictType/dropDown',
			params: {
				code: 'report_emergency_degree',
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.sysDictTypeList = res.data
				} else {
					that.$toast.alert({
						content: res.message,
						callback: result => {
							if (result.confirm) {
								uni.navigateBack({
									delta: 1
								})
							}
						}
					})
				}
			}
		})
	},
	openFile(url){
		wx.downloadFile({
		  url: url,
		  success: function (res) {
		    const filePath = res.tempFilePath
		    wx.openDocument({
		      filePath: filePath,
		      success: function (res) {
		        console.log('打开文档成功')
		      }
		    })
		  }
		})
	},
	del(index){
		this.wordList.splice(index,1)
		this.formData.reportFileId.splice(index,1)
	},
	changeHandleList(val){
		val == 0? this.isShowHandle = true : this.isShowHandle = false,
		this.formData.handleType = Number(val)+1 
	},
	//人员选择器
	getResponsible(val,label){
		console.log("责任人",val,label)
		this.formData.responsible = val[0]
		this.responsible = label
	},
	getcarbonCopyRecipients(val,label){
		// console.log(val,label)
		this.formData.carbonCopyRecipients = val
		this.carbonCopyRecipients = label
	},
	getApproval(val,label){
		// console.log(val,label)
		this.formData.approval = val
		this.approval = label
	},
	onConfirm(val){
		console.log(val)
	},
	onSearchInput(val){
		setTimeout(()=>{
			this.data = []
		},2000)
	},
}
